﻿#region Copyright(C) 2012 FI Ltd. All rights reserved.

// ==================================================================================================
// Copyright(C) 2006 FI Ltd. All rights reserved.
//
// SYSTEM NAME	:   FI.Net Application Framework
// COMPONENT ID :   FI.Web.Mvc
// COMPONENT DESC:  Extension for ASP.NET MVC
//
// CREATED DATE/BY:  18 Aug 2018 / Tian Mi
//
// REVISION HISTORY:	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

#endregion

using FI.Core.Utilities;
using System;
using System.Runtime.Serialization;

namespace FI.Core
{
    /// <summary>
    /// A entity type used to wrap <see cref="Exception"/> information.
    /// </summary>
    [DataContract(Namespace = Constants.Namespace)]
    public class ExceptionInfo
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ExceptionInfo"/> class.
        /// </summary>
        /// <param name="exception">The exception.</param>
        public ExceptionInfo(Exception exception)
        {
            Guard.ArgumentNotNull(exception, "exception");
            this.HelpLink = exception.HelpLink;
            this.Message = exception.Message;
            this.StackTrace = exception.StackTrace;
            this.ExceptionType = exception.GetType().ToString();
            if (exception.InnerException != null)
            {
                this.InnerException = new ExceptionInfo(exception.InnerException);
            }
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the help link.
        /// </summary>
        [DataMember]
        public string HelpLink { get; private set; }

        /// <summary>
        /// Gets the inner exception.
        /// </summary>
        [DataMember]
        public ExceptionInfo InnerException { get; private set; }

        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        /// <value>
        /// The message.
        /// </value>
        [DataMember]
        public string Message { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [shoud rethrow].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [shoud rethrow]; otherwise, <c>false</c>.
        /// </value>
        [DataMember]
        public bool WillRethrow { get; set; }

        /// <summary>
        /// Gets the stack trace.
        /// </summary>
        [DataMember]
        public string StackTrace { get; private set; }

        /// <summary>
        /// Gets the type of the exception.
        /// </summary>
        /// <value>
        /// The type of the exception.
        /// </value>
        [DataMember]
        public string ExceptionType { get; private set; }
        #endregion
    }
}
